<?

require('config_take.php');
require('include_take.php');
require('include_jobs.php');

session_start();
$self = auth();

if(($m = $_GET['m'])){
  $st = $db->prepare('select * from members where memberID = :mid');
  $st->bindParam(':mid', $m, PDO::PARAM_STR);
} else if($self){
  $st = $db->prepare('select * from members where loginID = :lid');
  $st->bindParam(':lid', $_SESSION['loginid'], PDO::PARAM_STR);
} else seeTop();

if($st->execute()) $user = $st->fetch(PDO::FETCH_OBJ);
else seeTop();

$title = $user->nickname . ' さんのページ';

require('header.php');
?>
<table id="userinfo"
  style="background-image:no-repeat top left url(<?= $user->image ?>)">
<caption class="name gender<?= $user->gender ?>">
<?= $user->nickname ?>
</caption>
<tr class="profile">
  <td colspan="2"><?= $user->profile ?></td>
</tr>
<tr>
  <td class="edit">
<?
if($_SESSION['loginid'] == $user->loginID)
  echo '<a href="edit_user.php">編集する</a>';
?>
  </td>
</tr>
</table>
<?
$st = $db->prepare('select * from jobs where buyer = :mid OR seller = :mid');
$st->bindParam(':mid', $user->memberID, PDO::PARAM_INT);
if($st->execute()) $jobs = $st->fetchAll(PDO::FETCH_OBJ);
if($jobs) print_jobs($db, $jobs, $user->memberID);

require('footer.php');

function seeTop(){
  header('Location: .', true, 302);
  exit();
}
